/**操作面板场景 */
class PanelScene extends ViewBase {
	public constructor() {
		super();
		super.Adaptive();
		this.skinName = "PanelSceneSkin";
		this.once(egret.Event.ADDED_TO_STAGE, this.Init, this);

	}

	/******DATA******/
	/**拼手速点击数 */
	private spellHandSpeed: number;
	/**点击状态 */
	private clickState: ShootControlState;
	//------VIEW--------------------------------
	/**游戏场景 */
	private gameScene: GameScene;
	/**摇杆 */
	private rocker: roleControl;
	/**发射键 */
	private shootControl: ShootControl;

	//------EUI---------------------------------
	/**返回主界面按钮 */
	private backBtn: eui.Button;
	/**加速按钮 */
	private speedUpBtn: eui.Image;
	/**摇杆中心圈 */
	private hand: eui.Image;
	/**摇杆外围圈 */
	private circle: eui.Image;
	/**摇杆容器 */
	private rockerGroup: eui.Group;
	/**结算界面 */
	private settlement: eui.Group;
	/**结算界面返回按钮 */
	private backBeginScene: eui.Image;
	/**射击按钮容器 */
	private shootGroup: eui.Group;
	/**射击按钮外围 */
	private shootCirle: eui.Image;
	/**技能按钮 */
	private skillBtn: eui.Image;
	/**技能能量条 */
	public skillEnergyBar: eui.Image;
	/**技能能量条背景 */
	public skillEnergyBG: eui.Image;
	//--------能量条---------------------
	/**能量条 */
	public progressBar: eui.ProgressBar;

	//----动画播放对象-------
	private click: egret.MovieClip;

	//滑动功能
	private slide: slideControl;

	/**初始化 */
	private Init() {
		this.dataInit();
		this.rockerInit();
		this.shootControlInit();
		this.eventInit();
		this.SlideInit();
	}
	/**发射键初始化 */
	private shootControlInit() {
		this.shootControl = new ShootControl(this.skillBtn, this.shootCirle, this.shootGroup, this.skillEnergyBar, this.skillEnergyBG, this);
		this.shootControl.RockerInit(this.stage);

	}
	public getShootControl() {
		return this.shootControl;
	}
	/**摇杆初始化 */
	private rockerInit() {
		this.rocker = new roleControl(this.hand, this.circle, this.rockerGroup);
		this.rocker.RockerInit(this.stage);
		
	}
	/**获取摇杆方向 */
	public GetRockerDir() {
		return this.rocker.getPosition();
	}

	/**数据初始化 */
	private dataInit() {
		this.spellHandSpeed = 0;
		this.clickState = ShootControlState.normal;
		this.gameScene = SceneManager.instance.GetGameSceneObj();
		this.click = FrameAnimation.getInstance().GetFrameAnimation("Click_ske_mc", 1000, 400, "Click_ske", -1);
		this.click.visible = false;
		this.addChild(this.click);
	}
	/**处理PK命令 */
	public dealPKOrder(rockerState: ShootControlState) {
		if (this.clickState != rockerState) {
			this.clickState = rockerState;
			if (rockerState == ShootControlState.spellHandSpeed) {
				this.shootGroup.visible = false;
				this.showClick();
			} else if (rockerState == ShootControlState.normal) {
				this.shootGroup.visible = true;
				this.hideClick();
			}
		}


	}

	/**获取点击次数 */
	public getClickNum(): number {
		let clickNum = this.spellHandSpeed;
		this.spellHandSpeed = 0;
		console.log("clickNum" + clickNum)
		return clickNum;
	}
	/**陀螺发射 */
	public TopShoot(dir: Vector_2) {
		this.gameScene.MyTopShoot(dir);

	}
	/**事件初始化 */
	private eventInit() {
		this.backBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.backBeginMain, this);
		this.speedUpBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.MyTopSpeedUpEvent, this);
	}
	/**自己陀螺加速事件 */
	private MyTopSpeedUpEvent(evt: egret.TouchEvent) {
		if (this.clickState == ShootControlState.normal) {
			this.gameScene.MyTopSpeedUp();
		} else if (this.clickState == ShootControlState.spellHandSpeed) {
			this.spellHandSpeed++;
		}

	}
	/**返回开始界面 */
	private backBeginMain() {
		SceneManager.instance.SitchScene(SceneName.beginScene);
	}
	/**处理结算 */
	private DealSettlement() {
		this.settlement.visible = true;
	}

	/*获取玩家的摇杆 */
	public getRock() {
		if (this.rocker == null) {
			console.log("获取的摇杆为空");
			return null;
		}


		return this.rocker;
	}

	public reset() {

	};
	public destroy() {

	};
	public clear() {
		this.backBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.backBeginMain, this);
		this.rocker.clearYaogan();
	};

	/**显示点击对象 */
	public showClick() {
		this.click.visible = true;
	}
	/**隐藏点击对象 */
	public hideClick() {
		this.click.visible = false;
	}
	//滑动功能初始化
	private SlideInit(){
		this.slide=new slideControl();
		this.slide.slideInit(this.stage,this.gameScene);
	}
}
/**发射按钮状态 */
enum ShootControlState {
	normal, spellHandSpeed
}
